﻿using UnityEngine;
using System.Collections;

public class UIName3D : MonoBehaviour
{
    public TextMesh text0;
    public TextMesh text1;
    public TextMesh text2;
    public TextMesh text3;
    public TextMesh text4;
	//工会名
	public TextMesh unionText0;
	public GameObject unionNameObj;
    public QuadTitle title;



    // Update is called once per frame
    void LateUpdate()
    {
        transform.LookAt(CameraTool.Instance.sceneCamera.transform);
        var eulerAngles = transform.rotation.eulerAngles;
        transform.rotation = Quaternion.Euler(0 - eulerAngles.x, CameraTool.Instance.sceneCamera.transform.localEulerAngles.y, 0);
    }

    public string text
    {
        get
        {
            return text0.text;
        }
        set
        {
            text0.text = value;
            text1.text = value;
            text2.text = value;
            text3.text = value;
            text4.text = value;
        }
    }

	public string UnionText
	{
		get
		{
			return unionText0.text;
		}
		set
		{
			unionText0.text = value;	
		}
	}


    public Color color
    {
        get
        {
            return text0.color;
        }
        set
        {
            text0.color = value;
        }
    }

    public void SetUinonServer(string unionName = "", int serverID = -1)
    {
        if (string.IsNullOrEmpty(unionName))
        {
            SwitchUnionName(false);
        }
        else
        {
            SwitchUnionName(true);
            if (Room.RoomManager.curSceneType == SceneType.TOWN)
                UnionText = string.Concat("<", unionName, ">");
        }
        if (serverID != -1 &&serverID!=0 && (Room.RoomManager.curSceneType == SceneType.FIELD || Room.RoomManager.curSceneType == SceneType.UNIONFIGHT))
        {
            SwitchUnionName(true);
            UnionText = string.Concat("<", serverID, "服", ">");
        }
    }

	public void SetTitle(string titleId)
    {
        if (string.IsNullOrEmpty(titleId))
        {
            SwitchTitle(false);
        }
        else
        {
            SwitchTitle(true);
            title.SetSpriteFormAtlas(titleId);
        }
    }
	public void SwitchUnionName(bool isActive)
	{
        if (isActive == true)
        {
            unionNameObj.SetActive(true);
            if (title.gameObject.transform.localPosition.y <= 0.6f&&title.gameObject.activeSelf)
                title.gameObject.transform.localPosition += new Vector3(0, 0.2f, 0);
        }
        else
        {
            unionNameObj.SetActive(false);
            if (title.gameObject.transform.localPosition.y >= 0.6f)
                title.gameObject.transform.localPosition = new Vector3(0, 0.503f, 0);
        }
	}

    public void SwitchTitle(bool isActive)
    {
        title.gameObject.SetActive(isActive);
    }
}
